<@pp.dropOutputFile/>
<#-- iterate table list-->
<#list doc.tables as table>

<#-- generate package name -->
<#assign package = doc.groupid?replace(".", "/")> 
<#assign package = package + "/" + doc.artifactid?replace(".", "/")>
<#assign package = package + "/" + table.moduleid?replace(".", "/")>
<#assign fileName = table.name?cap_first>
<#assign namespace = table.moduleid?cap_first + "/" + table.name?cap_first>
<@pp.changeOutputFile name="/main/" + package + "/action/" + fileName + "Action.java"/>
/*
 * File name : ${fileName}Action.java ${doc.date}
 * Copyright ${doc.copyright}. All rights reserved.
 */
package ${package?replace("/", ".")}.action;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import ${package?replace("/", ".")}.domain.${fileName};
import ${package?replace("/", ".")}.service.${fileName}Service;
import org.xust.common.pagination.domain.Page;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.opensymphony.xwork2.validator.annotations.ValidatorType;

import javax.servlet.http.HttpServletResponse;

/**
 * Class ${fileName}Action
 * ${fileName} action class.
 * @author ${doc.author}
 * @version ${doc.version}, ${doc.date}
 */
@Controller("${table.name?uncap_first}Action")
public class ${fileName}Action extends ActionSupport {

	private static final long serialVersionUID = 1L;

	private final static Log logger = LogFactory.getLog(${fileName}Action.class);
	
	@Autowired
	private ${fileName}Service ${table.name?uncap_first}Service;
	
	Map<String, Object> output;
	
	///////////////////////////Parameters for pagination
	private Integer rows;
	private Integer page;
	private Integer total;

	//////////////////////////Front page theme
	private String theme = "bootstrap";
	
	//////////////////////////Parameters for operations
	private Integer[] items;	//for delete
	private Integer id;
	private ${fileName} ${fileName?uncap_first};	//for add and update

	/**
	 * Request ${fileName} object data view.
	 * @return ${fileName} object data view.
	 */
	@Action(value="/${namespace}/showItems", results={
		@Result(name="success", location="items.ftl", type="freemarker")
	})
	public String doShowItems(){
		return SUCCESS;
	}
	
	/**
	 * Insert new ${fileName} object.
	 * @param ${fileName?uncap_first} New object.
	 * @return The id of new object which represented by value field of Result object.
	 */
	@Action(value="/${namespace}/add", results={
			@Result(name="success", location="/common/operateResult.ftl", type="freemarker"),
			@Result(name="input", location="/common/operateResult.ftl", type="freemarker")
	})
	public String doAdd(){
		output = new HashMap<String, Object>();
		org.xust.common.Result<Integer> result = ${table.name?uncap_first}Service.insert(${fileName?uncap_first});
		output.put("result", result);
		return SUCCESS;
	}
	
	/**
	 * Update ${fileName} object.
	 * @param ${fileName?uncap_first} New object.
	 * @return The id of new object which represented by value field of Result object.
	 */
	@Action(value="/${namespace}/update", results={
			@Result(name="success", location="/common/operateResult.ftl", type="freemarker"),
			@Result(name="input", location="/common/operateResult.ftl", type="freemarker")
	})
	public String doUpdate(){
		output = new HashMap<String, Object>();
		org.xust.common.Result<Integer> result = ${table.name?uncap_first}Service.update(${fileName?uncap_first});
		output.put("result", result);
		return SUCCESS;
	}

	/**
	 * Delete objects which id were included in items array.
	 * @param items Target ids.
	 * @return The number of rows affected which represented by value field of Result object.
	 */
	@Action(value="/${namespace}/deleteItems", results={
		@Result(name="success", location="/common/operateResult.ftl", type="freemarker"),
		@Result(name="input", location="/common/operateResult.ftl", type="freemarker")
	})
	public String doDeleteItems(){
		output = new HashMap<String, Object>();
		org.xust.common.Result<Integer> result = ${table.name?uncap_first}Service.deleteItems(items);
		output.put("result", result);
		return SUCCESS;
	}

	/**
	 * Retrieve objects in specified page.
	 * @param page Page number.
	 * @param rows The number of rows.
	 * @param total The number of total rows.
	 * @return Target objects.
	 */
	@Action(value="/${namespace}/findPageData", results={
		@Result(name="success", location="pageData.ftl", type="freemarker")
	})
	public String doFindPageData(){
		output = new HashMap<String, Object>();
		total = ${table.name?uncap_first}Service.size().getValue();
		Page pageInfo = new Page(page, rows, total);
		output.put("rows", ${table.name?uncap_first}Service.findPage(pageInfo));
		return SUCCESS;
	}
	
	/**
	 * Retrieve object by id.
	 * @param id Target id.
	 * @return Target object.
	 */
	@Action(value="/${namespace}/findById", results={
		@Result(name="success", location="objectData.ftl", type="freemarker")
	})
	public String doFindById(){
		output = new HashMap<String, Object>();
		output.put("object", ${table.name?uncap_first}Service.findById(id));
		return SUCCESS;
	}	
	
	<#list table.apis as api>
	<#if (api.name != "findPageDate") && (api.name != "deleteItems") && (api.name != "add") && (api.name != "showItems")>
	/**
	 * <#if api.comment?exists>${api.comment}</#if>.
	 <#list api.params as param>
	 * @param ${param.name} ${param.type}.
	 </#list>
	 * @return <#if api.return?exists>${api.return}</#if>.
	 */
	@Action(value="/${namespace}/${api.name}", results={
		@Result(name="success", location="${api.name}Data.ftl", type="freemarker")
	})
	public String do${api.name?cap_first}(){
		output = new HashMap<String, Object>();
		output.put("object","OK");
		return SUCCESS;
	}	
	</#if>
	</#list>
	
	public Map<String, Object> getOutput() {
		return output;
	}

	public void setOutput(Map<String, Object> output) {
		this.output = output;
	}

	public Integer getRows() {
		return rows;
	}

	public void setRows(Integer rows) {
		this.rows = rows;
	}

	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public Integer getTotal() {
		return total;
	}

	public void setTotal(Integer total) {
		this.total = total;
	}

	public String getTheme() {
		return theme;
	}

	public void setTheme(String theme) {
		this.theme = theme;
	}
	
	public Integer[] getItems() {
		return items;
	}

	public void setItems(Integer[] items) {
		this.items = items;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}


	public ${table.name?cap_first}Service get${table.name?cap_first}Service() {
		return ${table.name?uncap_first}Service;
	}

	public void set${table.name?cap_first}Service(${table.name?cap_first}Service ${table.name?uncap_first}Service) {
		this.${table.name?uncap_first}Service = ${table.name?uncap_first}Service;
	}

	public ${fileName} get${fileName}() {
		return ${fileName?uncap_first};
	}

	public void set${fileName}(${fileName} ${fileName?uncap_first}) {
		this.${fileName?uncap_first} = ${fileName?uncap_first};
	}

}
</#list>